window.onload = function () {
    const tel = document.getElementById("telephone");
    const newpad = document.getElementById("newpsd");
    const oldpad = document.getElementById("oldpsd");

    tel.addEventListener('focus', function () {
        tel.removeAttribute('placeholder')
    });
    tel.addEventListener('blur', function () {
        tel.setAttribute('placeholder', '请输入绑定手机号')
    });
    newpad.addEventListener('focus', function () {
        newpad.removeAttribute('placeholder')
    });
    newpad.addEventListener('blur', function () {
        newpad.setAttribute('placeholder', '必填')
    });
    oldpad.addEventListener('focus', function () {
        oldpad.removeAttribute('placeholder')
    });
    oldpad.addEventListener('blur', function () {
        oldpad.setAttribute('placeholder', '必填')
    });
}

function findPassWord() {
    //手机号验证
    const phone = document.getElementById("telephone").value;
    const reg1 = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
    const password = document.getElementById("newpsd").value;
    const reg2 = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*.])[a-zA-Z\d#@!~%^&*.]{6,}$/;
    const testpsd = document.getElementById("oldpsd").value;

    if (reg1.test(phone) && reg2.test(password) && testpsd == password) {
        var flag = confirm("确定提交？");
        if(flag){
            axios.post("http://localhost:8081/admin/findPassWord",
                {tellphone:phone,password:password}).then(res => {
                    alert(res.data.msg);
                    if(res.data.state){
                        window.opener=null;
                        window.open('','_self');
                        window.close();
                        location.href = "../html/login.html";
                    }
            })
        }
    }
}

function Ipone() {
    //手机号验证
    const phone = document.getElementById("telephone").value;
    const reg1 = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
    if (!reg1.test(phone)) {
        myphone.innerHTML = "<img src='../img/no.png' style='vertical-align: middle;'>";
        return false;
    } else {
        myphone.innerHTML = "<img src='../img/yes.png' style='vertical-align: middle;'>";
        return true;
    }
}

function pdd() {
    const password = document.getElementById("newpsd").value;
    const reg2 = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*.])[a-zA-Z\d#@!~%^&*.]{6,}$/;
    if (!reg2.test(password)) {
        first.innerHTML = "<img src='../img/no.png' style='vertical-align: middle;'>";
        return false;
    } else {
        first.innerHTML = "<img src='../img/yes.png' style='vertical-align: middle;'>";
        return true;
    }
}

function test() {
    const password = document.getElementById("newpsd").value;
    const testpsd = document.getElementById("oldpsd").value;
    if (testpsd != password) {
        textFirst.innerHTML = "<img src='../img/no.png' style='vertical-align: middle;'>";
        return false;
    } else {
        textFirst.innerHTML = "<img src='../img/yes.png' style='vertical-align: middle;'>";
        return true;
    }
}